# coding=utf-8
# --------------------------
# @Time    : 18-2-6 下午3:07
# @Author  : knight
# @File    : split_redis.py
# --------------------------
import oss2
import redis
import time
from datetime import datetime, date
import os


def oss_auth():
    auth = oss2.Auth('LTAIc0FJk4FahE7M', 'WQZ5T107RqM7blbnL6K7TnDfEjXWoO')
    bucket = oss2.Bucket(auth, 'oss-cn-shanghai.aliyuncs.com', 'vdodev-smpv')
    return bucket


def date_to_stamp(date_time):
    """

    :param date_time: datetime
    :return:
    """
    return time.mktime(date_time.timetuple())


def parse_redis_item(item):
    """

    :param item: str,
        testInput/SQ2108/20171118/Channel_09/Append/1510966292.mp4
    :return:
    """
    return item.split('/')[1:4]


def redis_split():
    """
    分发当天redis数据
    number: 需要生成的redis数据量(条)
    eg: testInput/SQ2108/20171118/Channel_09/Append/1510966292.mp4'
        10.255.131.77
    :return:
    """
    pool = redis.ConnectionPool(host='10.255.131.77', port=6379, password='redisPassw0rd',
                                db='0', decode_responses=True)
    r = redis.Redis(connection_pool=pool)
    count = 0
    testDir1 = '/data/ossfs/testInput/SQ2106/20180409/Channel_03/Append/'
    testDir2 = '/data/ossfs/testInput/SQ2110/20180409/Channel_02/Append/'
    testDir3 = '/data/ossfs/testInput/SQ2123/20180409/Channel_02/Append/'
    testDir4 = '/data/ossfs/testInput/SQ2124/20180409/Channel_06/Append/'
    testDir5 = '/data/ossfs/testInput/SQ2128/20180409/Channel_02/Append/'

    for root, dirs, files in os.walk(testDir1):
        for file in files:
            vdoName = 'testInput/SQ2106/20180409/Channel_03/Append/%s'%(file)
            r.lpush('SQ2106_wait_fetch_list0318', vdoName)
   
    for root, dirs, files in os.walk(testDir2):
        for file in files:
            vdoName = 'testInput/SQ2110/20180409/Channel_02/Append/%s'%(file)
            r.lpush('SQ2110_wait_fetch_list0318', vdoName)


    for root, dirs, files in os.walk(testDir3):
        for file in files:
            vdoName = 'testInput/SQ2123/20180409/Channel_02/Append/%s'%(file)
            r.lpush('SQ2123_wait_fetch_list0318', vdoName)


    for root, dirs, files in os.walk(testDir4):
        for file in files:
            vdoName = 'testInput/SQ2124/20180409/Channel_06/Append/%s'%(file)
            r.lpush('SQ2124_wait_fetch_list0318', vdoName)

    for root, dirs, files in os.walk(testDir5):
        for file in files:
            vdoName = 'testInput/SQ2128/20180409/Channel_02/Append/%s'%(file)
            r.lpush('SQ2128_wait_fetch_list0318', vdoName)
            print(vdoName)
if __name__ == '__main__':
    redis_split()
